package com.ruoyi.chat.util;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ruoyi.chat.domain.ChatMessage;
import org.springframework.stereotype.Component;

import javax.websocket.EncodeException;
import javax.websocket.Encoder;
import javax.websocket.EndpointConfig;

public class ChatMessageEncoder implements Encoder.Text<ChatMessage>{
    @Override
    public String encode(ChatMessage chatMessage) throws EncodeException {
        System.out.println("encoding");
        return new GsonBuilder()
                .setDateFormat("yyyy-MM-dd HH:mm:ss")
                .create()
                .toJson(chatMessage);
    }

    @Override
    public void init(EndpointConfig endpointConfig) {

    }

    @Override
    public void destroy() {

    }
}